home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / misc / math / MathFX_src.lha / fxdtik.c < prev    next >
C/C++ Source or Header  |  1995-12-20  |  2KB  |  73 lines

  1. /* If tick == 0, this works out a "nice" interval, so that there */
  2. /* are between 3 and 7.5 major tick intervals in the input range */
  3. /* "vmin" to "vmax". Using this value for the tick interval or   */
  4. /* supplied value, it also computes "prec" which specifies       */
  5. /* the number of places that should be written after the decimal */
  6. /* point. The recommended number of subticks is returned in      */
  7. /* "nsubt" unless the routine is entered with a non-zero value   */
  8. /* of "nsubt". The output variable "mode" is set to 0 if         */
  9. /* labels are to be written in floating-point format, or to 1 if */
  10. /* they are to be written in fixed-point format.                 */
  11.                                                                 
  12. #include "mathfx.h"
  13. #include <math.h>
  14.  
  15.  
  16.  
  17. void fxdtik(vmin, vmax, tick, nsubt, mode, prec)
  18. float vmin, vmax, *tick;
  19. int *nsubt, *mode, *prec;
  20. {
  21.       
  22.       float t1, t2, vmod;
  23.       int msd, np, ns;
  24.  
  25.       vmod = max(fabs(vmin),fabs(vmax));
  26.       *mode = 0;
  27.       if (vmod < 1.0e-2 || vmod > 1.0e6) *mode = 1;
  28.       t1 = (float)log10(vmod);
  29.       msd = (int)t1;
  30.  
  31.       t1 = (float)log10(fabs(vmax-vmin));
  32.       np = (int)t1;
  33.       t1 = t1 - np;
  34.       
  35.       if (t1 > 0.7781512503) {
  36.         t2 = 2.0 ;
  37.         ns = 4;
  38.       }
  39.       else if (t1 > 0.4771212549) {
  40.         t2 = 1.0 ;
  41.         ns = 5;
  42.       }
  43.       else if (t1 > 0.1760912591) {
  44.         t2 = 5.0;
  45.         ns = 5;
  46.         np = np-1;
  47.       }
  48.       else  {
  49.         t2 = 2.0;
  50.         ns = 4;
  51.         np = np-1;
  52.       }
  53.  
  54.       if (*tick == 0.0) {
  55.         *tick = t2 * pow(10.0,(double)np);
  56.         if (vmin > vmax) *tick = -*tick;
  57.         if (*nsubt == 0) *nsubt = ns;
  58.         if (*mode != 0) 
  59.           *prec = msd - np;
  60.         else
  61.           *prec = max(-np,0);
  62.       }
  63.       else  {
  64.         t1 = (float)log10(fabs(*tick));
  65.         np = (int)t1;
  66.         if (*mode != 0) 
  67.           *prec = msd - np + 1;
  68.         else
  69.           *prec = max(-np+1,0);
  70.       }
  71. }
  72.  
  73.